using System;
using ST.Domain.Entities;
using ST.Domain.IRepositories;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace ST.EntityFrameworkCore.Repositories
{
    public class UserRepository:RepositoryBase<User>,IUserRepository
    {
        public UserRepository(STDbContext dbContext) : base(dbContext)
        {
        }

        public User CheckUser(string userName, string password)
        {
            return _dbContext.Set<User>().FirstOrDefault(it => it.UserName == userName && it.Password == password);
        }

        public async Task<User> GetWithRoles(Guid id)
        {
            var user =await _dbContext.Set<User>().FirstOrDefaultAsync(it => it.Id == id);
            if (user != null)
            {
                user.UserRoles =await _dbContext.Set<UserRole>().Where(it => it.UserId == id).ToListAsync();
            }
            return user;
        }
    }
}